

cc.Class({
    extends: cc.Component,

    properties: {
        //每十层生成的金币数量.
        generateNum: 0,

        gameNode:{
            default: null,
            type: cc.Node
        },
        //金币预制体.
        coinPrefab:{
            default: null,
            type: cc.Prefab
        }
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        this.game = this.gameNode.getComponent('Game');
    },

    start () {

    },

    // update (dt) {},

    //在上下界范围内生成固定数量的金币.
    createCoins(min,max){
        for (let i = 0, l = this.generateNum; i < l; i++) {
            var clone = cc.instantiate(this.coinPrefab);
            clone.parent = this.node;
            var x = cc.randomMinus1To1() * 500;
            var y = min + cc.random0To1() * (max - min);
            clone.position = cc.v2(x,y);
            clone.getComponent('Coin').game = this.game;
        }
    },

    //在固定位置生成金币.
    createCoin(x,y){
        var clone = cc.instantiate(this.coinPrefab);
        clone.parent = this.node;
        clone.position = cc.v2(x,y);
        clone.getComponent('Coin').game = this.game;
    },
});
